<?php

$pathinfo = pathinfo(__FILE__);
preg_match('/.+(?=wp-content)/', $pathinfo['dirname'], $match);
$pathNeeded = preg_replace('/\ /', '/', $match[0]);
require_once($pathNeeded . 'wp-load.php'); //refer to wp-load to use instruction
// print_r($_REQUEST);


if (isset($_POST['fullName']) && isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['idDealFlight'])
	&& isset($_POST['address'])) {
    
    $dealFlightInfo = DealFlight::get($_POST['idDealFlight']);
    if ($dealFlightInfo) {

        if($dealFlightInfo[0]->type_travel == DealFlight::DEAL){
	    $typeRequest = RequestAQoute::REQUEST_A_DEAL;
	}else{
	    if($dealFlightInfo[0]->type_travel == DealFlight::FLIGHT){
		$typeRequest = RequestAQoute::REQUEST_A_FLIGHT;
	    }
	}
        $typeFlights = DealFlight::ROUNDTRIP;

        $startLocation = $dealFlightInfo[0]->start_location;
        $endLocation = $dealFlightInfo[0]->end_location;


        $startDate = $dealFlightInfo[0]->start_time;

        $listDate = explode(" ", $startDate);
        $day = $listDate[0];
        $listday = explode('-', $day);
        $dayStartTime = $listday[2] . '/' . $listday[1] . '/' . $listday[0];


        $endTime = $dealFlightInfo[0]->end_time;
        $listDate = explode(" ", $endTime);
        $day = $listDate[0];
        $listday = explode('-', $day);
        $dayEndTime = $listday[2] . '/' . $listday[1] . '/' . $listday[0];
        //echo $dayEndTime;
        $adult = $dealFlightInfo[0]->adult;
        $children = $dealFlightInfo[0]->children;
        $class = $dealFlightInfo[0]->class;
        $infant = $dealFlightInfo[0]->infant;
        $city = $dealFlightInfo[0]->city;

        $ds_startlocation_all[0] = $startLocation;
        $ds_endlocation_all[0] = $endLocation;
        $ds_startTime_all[0] = $dayStartTime;
        $ds_EndTime_all[0] = $dayEndTime;
        $price = $dealFlightInfo[0]->price;

        RequestAQoute::insertRequestAQoute($typeFlights, $_POST['fullName'], $_REQUEST['email'], $_REQUEST['phone'], 
		$ds_startlocation_all, $ds_endlocation_all, $ds_startTime_all, $ds_EndTime_all, $adult, $children, $class, 
		$infant, $city, $typeRequest,$price, $_POST['address']);
    }
}
//} else {
//
//
//    $FlightInfo = DealFlight::get($_POST['idFlight']);
//
//    if ($FlightInfo) {
//
//        //print_r($dealFlightInfo);
//        $typeRequest = RequestAQoute::REQUEST_A_FLIGHT;
//        $typeFlights = DealFlight::ROUNDTRIP;
//
//        $startLocation = $FlightInfo[0]->start_location;
//        $endLocation = $FlightInfo[0]->end_location;
//
//
//        $startDate = $FlightInfo[0]->start_time;
//
//        $listDate = explode(" ", $startDate);
//        $day = $listDate[0];
//        $listday = explode('-', $day);
//        $dayStartTime = $listday[2] . '/' . $listday[1] . '/' . $listday[0];
//
//
//        $endTime = $FlightInfo[0]->end_time;
//        $listDate = explode(" ", $endTime);
//        $day = $listDate[0];
//        $listday = explode('-', $day);
//        $dayEndTime = $listday[2] . '/' . $listday[1] . '/' . $listday[0];
//        //echo $dayEndTime;
//        $adult = $FlightInfo[0]->adult;
//        $children = $FlightInfo[0]->children;
//        $class = $FlightInfo[0]->class;
//        $infant = $FlightInfo[0]->infant;
//        $city = $FlightInfo[0]->city;
//        //$typeFlights = $_REQUEST['typeFlights'];
//        
//        $ds_startlocation_all[0] = $startLocation;
//        $ds_endlocation_all[0] = $endLocation;
//        $ds_startTime_all[0] = $dayStartTime;
//        $ds_EndTime_all[0] = $dayEndTime;
//        
//        $price = $FlightInfo[0]->price;
//        if($price == ""){ $price = 0;}
//       echo RequestAQoute::insertRequestAQoute($typeFlights, $_POST['fullName'], $_REQUEST['email'], $_REQUEST['phone'], $ds_startlocation_all, $ds_endlocation_all, $ds_startTime_all, $ds_EndTime_all, $adult, $children, $class, $infant, $city, $typeRequest,$price);
//    }
//}